from aiogram_dialog import Dialog, Window
from aiogram_dialog.widgets.input import TextInput
from aiogram_dialog.widgets.kbd import Back, Button, Cancel, SwitchTo, Url
from aiogram_dialog.widgets.text import Format

from src.bot.dialogs.extras import copy_start_data_to_ctx
from src.bot.dialogs.widgets import LocaleText
from src.bot.states import PaymentSG

from .handlers import check_payment, select_payment_method, validate_activation_code

select_payment_method_window = Window(
    LocaleText("select-payment-method-msg"),
    Button(
        LocaleText("activation-code-btn"),
        id="activation_code",
        on_click=select_payment_method,
    ),
    Button(LocaleText("fondy-btn"), id="fondy", on_click=select_payment_method),
    Cancel(LocaleText("back-btn")),
    state=PaymentSG.select_payment_method,
)

confirm_payment_window = Window(
    LocaleText("payment-info-msg"),
    Url(LocaleText("pay-btn"), Format("{dialog_data[bill_link]}")),
    Button(
        LocaleText("check-payment-btn"), "check_payment_btn", on_click=check_payment
    ),
    Back(LocaleText("back-btn")),
    state=PaymentSG.confirm_payment,
)

enter_activation_code_window = Window(
    LocaleText("enter-activation-code-msg"),
    TextInput("activation_code", str, on_success=validate_activation_code),
    SwitchTo(
        LocaleText("back-btn"),
        id="back_btn",
        state=PaymentSG.select_payment_method,
    ),
    state=PaymentSG.enter_activation_code,
)

create_payment_dialog = Dialog(
    select_payment_method_window,
    confirm_payment_window,
    enter_activation_code_window,
    on_start=copy_start_data_to_ctx,
)
